package com.mall.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hqj.utils.ReturnUtil;
import com.mall.db.domain.Comments;
import com.mall.db.service.CommentsService;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/goods/comments")
public class CommentController extends BaseController<Comments> {

    @Resource(name = "commentsService")
    public CommentsService cs;

    @Override
    public Map<String, Object> find(Comments comments) {
        PageHelper.startPage(comments.getPage(),comments.getLimit());
        QueryWrapper qw=new QueryWrapper();
        if(!StringUtils.isEmpty(comments.getPId())){
            qw.eq("p_id",comments.getPId());

        }
        if(!StringUtils.isEmpty(comments.getUId())){
            qw.eq("u_id",comments.getUId());

        }
        List<Comments> list=cs.list(qw);
        PageInfo<Comments> page= new PageInfo<>(list,comments.getLimit());
        return findMap(page.getList(),page.getTotal());
    }

    @Override
    public Map<String, Object> delete(Comments comments) {
        boolean b=false;
         if(!StringUtils.isEmpty(comments.getId())){
              b=cs.removeById(comments.getId());
         }

        return ReturnUtil.aid("删除",b,comments);
    }
}
